import request from '@/utils/request'
// import qs from 'qs'

// 日志配置

// 各模块日志开关设置
export function getLogModelInfo (params) {
  var data = fromData(params)
  return request({
    url: '/log/getLogModelInfo',
    method: 'post',
    data
  })
}

// 获取本地日志存储参数
export function getLogInfo (params) {
  var data = fromData(params)
  return request({
    url: '/log/getLogInfo',
    method: 'post',
    data
  })
}

// 设置各模块日志开关
export function editLogModel (params) {
  var data = fromData(params)
  return request({
    url: '/log/editLogModel',
    method: 'post',
    data
  })
}

// 设置本地日志存储参数
export function editLog (params) {
  var data = fromData(params)
  return request({
    url: '/log/editLog',
    method: 'post',
    data
  })
}

// 服务器日志配置

// 修改服务器日志配置
export function editServiceLog (params) {
  var data = fromData(params)
  return request({
    url: '/log/editServiceLog',
    method: 'post',
    data
  })
}

// 删除服务器日志配置
export function delServiceLog (params) {
  var data = fromData(params)
  return request({
    url: '/log/del_serviceLog',
    method: 'post',
    data
  })
}

// 增加服务器日志配置
export function addServiceLog (params) {
  var data = fromData(params)
  return request({
    url: '/log/addServiceLog',
    method: 'post',
    data
  })
}

// 查看服务器日志配置列表
export function getServiceLogArray (params) {
  var data = fromData(params)
  return request({
    url: '/log/getServiceLogArray',
    method: 'post',
    data
  })
}

// 数据日志

// 导出
export function exportDpLog (params) {
  var data = fromData(params)
  return request({
    url: '/dp_log/exportSearchLog',
    method: 'post',
    responseType: 'blob',
    data
  })
}

// 查询数据日志
export function searchDpLog (params) {
  var data = fromData(params)
  return request({
    url: '/dp_log/searchLog',
    method: 'post',
    data
  })
}

// 清空日志
export function cleanDpLog (params) {
  var data = fromData(params)
  return request({
    url: '/dp_log/cleanDpLog',
    method: 'post',
    data
  })
}

// 获取所属模块信息
export function getDpMode (params) {
  var data = fromData(params)
  return request({
    url: '/dp_log/getMode',
    method: 'post',
    data
  })
}

// 日志报表

// 事件类型分析统计
export function searchEvent (params) {
  var data = fromData(params)
  return request({
    url: '/report_log/searchEvent',
    method: 'post',
    data
  })
}

// 协议类型分析统计
export function searchL4type (params) {
  var data = fromData(params)
  return request({
    url: '/report_log/searchL4type',
    method: 'post',
    data
  })
}

// 模块统计
export function reportLogModule (params) {
  var data = fromData(params)
  return request({
    url: '/report_log/module',
    method: 'post',
    data
  })
}

// 统计下载
export function reportLogDownload (params) {
  var data = fromData(params)
  return request({
    url: '/report_log/download',
    method: 'post',
    responseType: 'blob',
    data
  })
}

// 管理日志

// 导出
export function exportMgmtLog (params) {
  var data = fromData(params)
  return request({
    url: '/mgmt_log/exportSearchLog',
    method: 'post',
    responseType: 'blob',
    data
  })
}

// 查询管理日志
export function searchMgmtLog (params) {
  var data = fromData(params)
  return request({
    url: '/mgmt_log/searchLog',
    method: 'post',
    data
  })
}

// 清空日志
export function cleanMgmtLog (params) {
  var data = fromData(params)
  return request({
    url: '/mgmt_log/cleanMgmtLog',
    method: 'post',
    data
  })
}

// 获取所属模块信息
export function getMgmtMode (params) {
  var data = fromData(params)
  return request({
    url: '/mgmt_log/getMode',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
